import cv2

# 获取内置的检测器
face_cascade = cv2.CascadeClassifier(
    "/opt/anaconda3/lib/python3.8/site-packages/cv2/data/haarcascade_eye_tree_eyeglasses.xml")
# 读取图片
img = cv2.imread("face.jpg")
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# 探测图片中的人脸
eyes = face_cascade.detectMultiScale(gray)

print("发现{0}个眼睛！".format(len(eyes)))

for (x, y, w, h) in eyes:
    cv2.circle(img, (int((x + x + w) / 2), int((y + y + h) / 2)), int(w / 2), (0, 255, 0), 2)

cv2.imshow("find faces!", img)
cv2.imwrite("face_out.jpg", img)
cv2.waitKey(0)
